//
//  MAMutablePolylineView.m
//  地图
//
//  Created by dllo on 16/5/20.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "MAMutablePolylineView.h"

@implementation MAMutablePolylineView

- (instancetype)initWithMutablePolyline:(MAMutablePolyline *)polyline {
    /*!
     @brief 初始化并返回一个overlay view
     @param overlay 关联的overlay对象
     @return 初始化成功则返回overlay view,否则返回nil
     */
    self = [super initWithOverlay:polyline];
    if (self) {
        
    }
    return self;
}

- (MAMutablePolyline *)mutablePolyline
{
    return (MAMutablePolyline *)self.overlay;
}

#pragma mark - 覆盖
/** 参考所做的改变*/
- (void)referenceDidChange
{
    [super referenceDidChange];
    
    MAMutablePolyline *polyline = [self mutablePolyline];
    
    if (polyline.points == NULL || polyline.pointCount < 2)
    {
        return;
    }
    
    self.glPoints = [self glPointsForMapPoints:polyline.points count:polyline.pointCount];
    self.glPointCount = polyline.pointCount;
}

/** 渲染*/
- (void)glRender
{
    if (self.glPoints == NULL || self.glPointCount < 2 || self.lineWidth <= 0.0)
    {
        return;
    }
    
    /*!
     使用OpenGLES 绘制线
     @param points       OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
     @param pointCount   点个数
     @param strokeColor  线颜色
     @param lineWidth    OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
     @param looped       是否闭合, 如polyline会设置NO, polygon会设置YES.
     @param lineJoinType 线连接点样式
     @param lineCapType  线端点样式
     @param lineDash     是否是虚线
     */
    [self renderLinesWithPoints:self.glPoints
                     pointCount:self.glPointCount
                    strokeColor:self.strokeColor
                      lineWidth:[self glWidthForWindowWidth:self.lineWidth]
                         looped:NO
                   LineJoinType:self.lineJoinType
                    LineCapType:self.lineCapType
                       lineDash:self.lineDash];
}


@end
